import {  marked } from "marked";
import { markedHighlight } from "marked-highlight";
import hljs from "highlight.js";

marked.setOptions({
    renderer: new marked.Renderer(),
    gfm: true,
    pedantic: false,
    sanitize: false,
    tables: true,
    breaks: true,
    smartLists: true,
    smartypants: false,
    mangle: false,
    headerIds: false,
    xhtml: false,
    highlight: function (code, land) {
        const language = hljs.getLanguage(land) ? land : 'plaintext';
        return hljs.highlight(code, { language }).value;
    },
    langPrefix: 'hljs language-',
});
// const mark = new Marked(
//     markedHighlight({
//         headerIds: false,
//         langPrefix: 'hljs language-',
//         highlight(code, lang, info) {
//             const language = hljs.getLanguage(lang) ? lang : 'plaintext';
//             return hljs.highlight(code, { language }).value;
//         }
//     })
// )
/*
    将markdown转换为html
*/
export const markdownToHtml = (content) => {
    return new Promise((resolve) => {
        let htmltext = marked.parse(content)
        // let htmltext = mark.parse(content)
        resolve(htmltext)
    })
}